<?php
namespace app\index\model;
use think\Model;
use think\Db;
class PromotionModel extends Model{
	public function getSnList(){
		$where=array(
			'status'=>1,
			'used'=>1
		);
		$list=Db::name('sn')->where($where)->order('usetime desc')->limit(20)->select();
		if(!empty($list['0'])){
			foreach($list as $k=>$vo){
				$name=Db::name('sntype')->field('name')->where('type',$vo['type'])->find();
				$list[$k]['name']=$name['name'];
			}
		}
		return $list;
	}
	
	function getSntype($type){
		$tname=Db::name('sntype')->where(array("type"=>$type))->find();
		return $tname["name"];
	}
	function getSntypeList(){
		$list=Db::name('sntype')->where(array("status"=>1))->select();
		return $list;
	}
	function zm($len, $chars=null)
	{
	    if (is_null($chars)){
	        $chars = "abcdefghijklmnopqrstuvwxyz";
	    }  
	    mt_srand(10000000*(double)microtime());
	    for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
	        $str .= $chars[mt_rand(0, $lc)];  
	    }
	    return $str;
	}
	
	function Keys($total,$prefix='',$endfix=''){
		//使用uniqid mt_rand 生成随机不重复字符串的方法
		$snKeys=array();
		while(count($snKeys) < $total) {
		     $snKeys[] = $prefix . md5(uniqid(mt_rand(), true)).$endfix;
		}
		return $snKeys;
	}
	
}
?>